﻿using Model;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class orderDal
    {
        /// <summary>
        /// 添加订单记录
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static int Addorder(ms_order order)
        {
            string sql = "insert into ms_order(order_sn,pay_sn,pay_type,merchant_id,user_id,user_tel,wxid,openid,goods_info,is_group,activity_id,group_num,expiration_time,prebook,order_price,discount_amount,discount_price,pay_price,user_coupon_id,integral,integral_grant,codes,consignee_name,consignee_tel,consignee_address,add_time,pay_time,team_time,ordertype,orderremark,orderdisksn,is_online,u_sage,sales_id) values(@order_sn,@pay_sn,@pay_type,@merchant_id,@user_id,@user_tel,@wxid,@openid,@goods_info,@is_group,@activity_id,@group_num,@expiration_time,@prebook,@order_price,@discount_amount,@discount_price,@pay_price,@user_coupon_id,@integral,@integral_grant,@codes,@consignee_name,@consignee_tel,@consignee_address,@add_time,@pay_time,@team_time,@ordertype,@orderremark,@orderdisksn,@is_online,@u_sage,@sales_id)";
            MySqlParameter[] values = new MySqlParameter[34];
            values[0] = new MySqlParameter("order_sn", order.order_sn);
            values[1] = new MySqlParameter("pay_sn", order.pay_sn);
            values[2] = new MySqlParameter("pay_type", order.pay_type);
            values[3] = new MySqlParameter("merchant_id", order.merchant_id);
            values[4] = new MySqlParameter("user_tel", order.user_tel);
            values[5] = new MySqlParameter("wxid", order.wxid);
            values[6] = new MySqlParameter("openid", order.openid);
            values[7] = new MySqlParameter("goods_info", order.goods_info);
            values[8] = new MySqlParameter("is_group", order.is_group);
            values[9] = new MySqlParameter("activity_id", order.activity_id);
            values[10] = new MySqlParameter("group_num", order.group_num);
            values[11] = new MySqlParameter("expiration_time", order.expiration_time);
            values[12] = new MySqlParameter("prebook", order.prebook);
            values[13] = new MySqlParameter("order_price", order.order_price);
            values[14] = new MySqlParameter("discount_amount", order.discount_amount);
            values[15] = new MySqlParameter("discount_price", order.discount_price);
            values[16] = new MySqlParameter("pay_price", order.pay_price);
            values[17] = new MySqlParameter("user_coupon_id", order.user_coupon_id);
            values[18] = new MySqlParameter("integral", order.integral);
            values[19] = new MySqlParameter("integral_grant", order.integral_grant);
            values[20] = new MySqlParameter("codes", order.codes);
            values[21] = new MySqlParameter("consignee_name", order.consignee_name);
            values[22] = new MySqlParameter("consignee_tel", order.consignee_tel);
            values[23] = new MySqlParameter("consignee_address", order.consignee_address);
            values[24] = new MySqlParameter("add_time", order.add_time);
            values[25] = new MySqlParameter("pay_time", order.pay_time);
            values[26] = new MySqlParameter("team_time", order.team_time);
            values[27] = new MySqlParameter("ordertype", order.ordertype);
            values[28] = new MySqlParameter("user_id", order.user_id);
            values[29] = new MySqlParameter("orderremark", order.orderremark);
            values[30] = new MySqlParameter("orderdisksn", order.orderdisksn);
            values[31] = new MySqlParameter("is_online", order.is_online);
            values[32] = new MySqlParameter("u_sage", order.u_sage);
            values[33] = new MySqlParameter("sales_id", order.sales_id);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 查用户订单列表
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static List<ms_order> Querybymerchantid(string merchant_id)
        {
            string sql = "select * from ms_order where merchant_id=@merchant_id order by id desc";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchant_id);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查商户营业额
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static double Querysummoney(string merchantid)
        {
            string sql = "select sum(pay_price) as money from ms_order where merchant_id=@merchant_id";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            double money = 0;
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            if (rd.Read())
            {
                if (!string.IsNullOrEmpty(rd["money"].ToString()))
                    money = Convert.ToDouble(rd["money"]);
            }
            rd.Close();
            return money;
        }
        /// <summary>
        /// 今日收益
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static double Querysdaymoney(string merchantid)
        {
            string sql = "select sum(pay_price) as money from ms_order where status=6 and merchant_id=@merchant_id and to_days(add_time)=to_days(Now())";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            double money = 0;
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            if (rd.Read())
            {
                if (!string.IsNullOrEmpty(rd["money"].ToString()))
                    money = Convert.ToDouble(rd["money"]);
            }
            rd.Close();
            return money;
        }
        /// <summary>
        /// 查今日订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> Querybytoday(string merchantid)
        {
            string sql = "select * from ms_order where merchant_id=@merchant_id and DATE(delivery_time_start) = CURDATE() ";
            // string sql = "select * from ms_order where merchant_id=@merchant_id and status=2 ";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查昨日订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> Querybyyestoday(string merchantid)
        {
            string sql = "select * from ms_order where merchant_id=@merchant_id and TO_DAYS(NOW())-TO_DAYS(add_time)=1 order by id desc";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查实时订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> QuerybyHour(string merchantid,string status)
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and codestatus=1 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            //string sql = "select * from ms_order where merchant_id=@merchant_id and orderdisksn is not null  order by id desc";
            //  string sql = "select * from ms_order where merchant_id=@merchant_id  and (is_online=2 and status=1)  or ( is_online=1  and status<>0 and `status`<>6 and u_sage=1 and codestatus=1) or(`status`=3 and codestatus=2)  order by id desc";
            string sql = "select * from ms_order where merchant_id=@merchant_id and  u_sage=3 and status=@status  and delivery_time_start>=CURDATE() order by id asc";
            MySqlParameter[] values = new MySqlParameter[2];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            values[1] = new MySqlParameter("status", status);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                order.packing_amount =Convert.ToDouble( rd["packing_amount"]);
                order.logistics_amount = Convert.ToDouble( rd["logistics_amount"]);
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        public static List<ms_order> QuerybyHour1(string merchantid, string status)
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and codestatus=1 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            //string sql = "select * from ms_order where merchant_id=@merchant_id and orderdisksn is not null  order by id desc";
            //  string sql = "select * from ms_order where merchant_id=@merchant_id  and (is_online=2 and status=1)  or ( is_online=1  and status<>0 and `status`<>6 and u_sage=1 and codestatus=1) or(`status`=3 and codestatus=2)  order by id desc";
            string sql = "select * from ms_order where merchant_id=@merchant_id and  u_sage=3 and status=@status and onreder=0  and delivery_time_start>=CURDATE() order by id asc";
            MySqlParameter[] values = new MySqlParameter[2];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            values[1] = new MySqlParameter("status", status);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查所有订单 
        /// </summary>
        /// <returns></returns>
        public static List<ms_order> QuerybyAll()
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and codestatus=1 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            //string sql = "select * from ms_order where merchant_id=@merchant_id and orderdisksn is not null  order by id desc";
            //  string sql = "select * from ms_order where merchant_id=@merchant_id  and (is_online=2 and status=1)  or ( is_online=1  and status<>0 and `status`<>6 and u_sage=1 and codestatus=1) or(`status`=3 and codestatus=2)  order by id desc";
            string sql = "select * from ms_order where  u_sage=3 and status=4 order by id asc";        
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, null);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordertype = rd["ordertype"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查今日未配送订单
        /// </summary>
        /// <returns></returns>
        public static List<ms_order> QueryDelivery(string merchantid)
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and codestatus=1 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            //string sql = "select * from ms_order where merchant_id=@merchant_id and orderdisksn is not null  order by id desc";
            //  string sql = "select * from ms_order where merchant_id=@merchant_id  and (is_online=2 and status=1)  or ( is_online=1  and status<>0 and `status`<>6 and u_sage=1 and codestatus=1) or(`status`=3 and codestatus=2)  order by id desc";
            string sql = "select * from ms_order where merchant_id=@merchant_id and u_sage=3 and status=2 and ordtype=1 and delivery_time_start>=CURDATE()";
            List<ms_order> odlist = new List<ms_order>();
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查今日未配送实时订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> QueryDelivery1(string merchantid)
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and codestatus=1 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            //string sql = "select * from ms_order where merchant_id=@merchant_id and orderdisksn is not null  order by id desc";
            //  string sql = "select * from ms_order where merchant_id=@merchant_id  and (is_online=2 and status=1)  or ( is_online=1  and status<>0 and `status`<>6 and u_sage=1 and codestatus=1) or(`status`=3 and codestatus=2)  order by id desc";
            string sql = "select * from ms_order where merchant_id=@merchant_id and u_sage=3 and status=1 and ordtype=2 and delivery_time_start>=CURDATE()";
            List<ms_order> odlist = new List<ms_order>();
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.delivery_time_start = rd["delivery_time_start"].ToString();
                order.delivery_time_end = rd["delivery_time_end"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查是否有未阅读订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static int Querycounnoreder(string merchantid)
        {
            string sql = "select count(*) as count from ms_order where merchant_id=@merchant_id  and  u_sage=3 and status=2 and onreder=0";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            int count = 0;
            if (rd.Read())
            {
                if (!string.IsNullOrEmpty(rd["count"].ToString()))
                    count = Convert.ToInt32(rd["count"]);
            }
            rd.Close();
            return count;
        }
        /// <summary>
        /// 查所有未阅读订单
        /// </summary>
        /// <returns></returns>
        public static int Querycounnoreder()
        {
            string sql = "select count(*) as count from ms_order where   u_sage=3 and status=4 and onreder=0";
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, null);
            int count = 0;
            if (rd.Read())
            {
                if (!string.IsNullOrEmpty(rd["count"].ToString()))
                    count = Convert.ToInt32(rd["count"]);
            }
            rd.Close();
            return count;
        }
        /// <summary>
        /// 查工作人员订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <param name="sales_id"></param>
        /// <returns></returns>
        public static List<ms_order> Querybysalesid(string merchantid, string sales_id)
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and codestatus=1 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            //string sql = "select * from ms_order where merchant_id=@merchant_id and orderdisksn is not null  order by id desc";
            string sql = "select * from ms_order where merchant_id=@merchant_id and sales_id=@sales_id and status=1 order by id desc";
            MySqlParameter[] values = new MySqlParameter[2];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            values[1] = new MySqlParameter("sales_id", sales_id);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查实时已完成订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> QuerybyHour1(string merchantid)
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and status=6 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            string sql = "select * from ms_order where merchant_id=@merchant_id and status=6 and TO_DAYS(add_time)=TO_DAYS(NOW()) order by id desc";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查待发货
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> Querynosend(string merchantid)
        {
            //string sql = "select * from ms_order where merchant_id=@merchant_id and status=6 and add_time>=NOW()-INTERVAL 1 HOUR order by id desc";
            string sql = "select * from ms_order where merchant_id=@merchant_id and status=3  order by id asc";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查待核销订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> Querycodes(string merchantid)
        {
            string sql = "select * from ms_order where merchant_id=@merchant_id and codestatus=1 order by id asc";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查物流订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_order> Querylog(string merchantid, string status)
        {
            string sql = "select * from ms_order where merchant_id=@merchant_id and status=@status order by id desc";
            MySqlParameter[] values = new MySqlParameter[2];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            values[1] = new MySqlParameter("status", status);
            List<ms_order> odlist = new List<ms_order>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_order order = new ms_order();
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                odlist.Add(order);
            }
            rd.Close();
            return odlist;
        }
        /// <summary>
        /// 查今日所有未打印订单
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static ms_order QueryPrint(string merchantid)
        {
            string sql = "select * from ms_order where merchant_id=@merchant_id and DATE(add_time) = CURDATE() and printstatus=0 order by id desc limit 1";
            //string sql = "select * from ms_order where merchant_id=@merchant_id  and printstatus=0 and  order by id desc limit 1";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            ms_order order = new ms_order();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            if (rd.Read())
            {
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();

            }
            rd.Close();
            return order;
        }
        /// <summary>
        /// 修改打印状态
        /// </summary>
        /// <param name="ordsn"></param>
        /// <returns></returns>
        public static int Updateprint(string ordsn)
        {
            string sql = "update ms_order set printstatus=1 where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("order_sn", ordsn);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 核销订单
        /// </summary>
        /// <param name="orderid"></param>
        /// <returns></returns>
        public static int Updatecodestatus(string ordsn)
        {
            string sql = "update ms_order set codestatus=2,status=6 where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("order_sn", ordsn);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="ordsn"></param>
        /// <returns></returns>
        public static int Claerordsn(string ordsn)
        {
            string sql = "update ms_order set codestatus=2,status=0 where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("order_sn", ordsn);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 扫码核销订单
        /// </summary>
        /// <param name="orderid"></param>
        /// <returns></returns>
        public static int Updatecodestatusscan(string order_sn)
        {
            string sql = "update ms_order set codestatus=2,status=6 where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("order_sn", order_sn);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="order_sn"></param>
        /// <returns></returns>
        public static int Clearordsn(string order_sn)
        {
            string sql = "update ms_order set codestatus=2,status=0 where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("order_sn", order_sn);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 修改支付金额
        /// </summary>
        /// <param name="order_sn"></param>
        /// <param name="price"></param>
        /// <returns></returns>
        public static int Updateprice(string order_sn, string price)
        {
            string sql = "update ms_order set pay_price=@pay_price where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[2];
            values[0] = new MySqlParameter("order_sn", order_sn);
            values[1] = new MySqlParameter("pay_price", price);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 修改订单用户信息
        /// </summary>
        /// <param name="order_sn"></param>
        /// <param name="user_tel"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static int Updateusertel(string order_sn, string user_tel, string uid)
        {
            string sql = "update ms_order set user_tel=@user_tel,user_id=@user_id where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[3];
            values[0] = new MySqlParameter("order_sn", order_sn);
            values[1] = new MySqlParameter("user_tel", user_tel);
            values[2] = new MySqlParameter("user_id", uid);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 通过订单号修改购买商品信息
        /// </summary>
        /// <param name="order_sn"></param>
        /// <param name="goods_info"></param>
        /// <returns></returns>
        public static int Updategoods_info(string order_sn, string goods_info, string price)
        {
            string sql = "update ms_order set goods_info=@goods_info,pay_price=@pay_price where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[3];
            values[0] = new MySqlParameter("order_sn", order_sn);
            values[1] = new MySqlParameter("goods_info", goods_info);
            values[2] = new MySqlParameter("pay_price", price);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 通过订单号查订单详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ms_order Querybysn(string ordsn)
        {
            string sql = "select * from ms_order where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("order_sn", ordsn);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            ms_order order = new ms_order();
            if (rd.Read())
            {
                order.id = rd["id"].ToString();
                order.order_sn = rd["order_sn"].ToString();
                order.pay_sn = rd["pay_sn"].ToString();
                order.pay_type = rd["pay_type"].ToString();
                order.merchant_id = rd["merchant_id"].ToString();
                order.user_id = rd["user_id"].ToString();
                order.user_tel = rd["user_tel"].ToString();
                order.openid = rd["openid"].ToString();
                order.goods_info = rd["goods_info"].ToString();
                order.activity_id = rd["activity_id"].ToString();
                order.prebook = rd["prebook"].ToString();
                order.order_price = rd["order_price"].ToString();
                order.discount_amount = rd["discount_amount"].ToString();
                order.pay_price = rd["pay_price"].ToString();
                order.refund_price = rd["refund_price"].ToString();
                order.user_coupon_id = rd["user_coupon_id"].ToString();
                order.integral = rd["integral"].ToString();
                order.consignee_name = rd["consignee_name"].ToString();
                order.consignee_tel = rd["consignee_tel"].ToString();
                order.consignee_address = rd["consignee_address"].ToString();
                order.express_id = rd["express_id"].ToString();
                order.express_name = rd["express_name"].ToString();
                order.courier_number = rd["courier_number"].ToString();
                order.status = rd["status"].ToString();
                order.add_time = rd["add_time"].ToString();
                order.pay_time = rd["pay_time"].ToString();
                order.deliver_time = rd["deliver_time"].ToString();
                order.receipt_time = rd["receipt_time"].ToString();
                order.over_time = rd["over_time"].ToString();
                order.cancel_time = rd["cancel_time"].ToString();
                order.refund_time = rd["refund_time"].ToString();
                order.refund_complete_time = rd["refund_complete_time"].ToString();
                order.u_sage = rd["u_sage"].ToString();
                order.onreder = rd["onreder"].ToString();
                order.ordtype = rd["ordtype"].ToString();
                order.packing_amount =Convert.ToDouble( rd["packing_amount"].ToString());
                order.logistics_amount = Convert.ToDouble(rd["logistics_amount"].ToString());
                order.coupon_amount = Convert.ToDouble(rd["coupon_amount"].ToString());
            }
            return order;
        }
        /// <summary>
        /// 通过订单ID核销订单
        /// </summary>
        /// <param name="ordsn"></param>
        /// <returns></returns>
        public static int Updateord(string ordid)
        {
            string sql = "update ms_order set status=6 where id=@id";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("id", ordid);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 发物流
        /// </summary>
        /// <param name="ordsn">订单号</param>
        /// <param name="courier_number">快递单号</param>
        /// <param name="express_name">快递公司</param>
        /// <returns></returns>
        public static int Logistics(string ordsn, string courier_number, string express_name)
        {
            string sql = "update ms_order set status=5,express_name=@express_name,courier_number=@courier_number where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[3];
            values[0] = new MySqlParameter("order_sn", ordsn);
            values[1] = new MySqlParameter("express_name", express_name);
            values[2] = new MySqlParameter("courier_number", courier_number);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 完成配送
        /// </summary>
        /// <param name="ordsn"></param>
        /// <param name="courier_number"></param>
        /// <param name="express_name"></param>
        /// <returns></returns>
        public static int Updatestatus(string ordsn,string status)
        {
            string sql = "update ms_order set status=@status where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[2];
            values[0] = new MySqlParameter("order_sn", ordsn);
            values[1] = new MySqlParameter("status", status);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 查询用户在该商户消费金额
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static int Querysummoneybyuid(string uid, string merchantid)
        {
            string sql = "select sum(pay_price) as money from ms_order where user_id=@user_id and merchant_id=@merchant_id and status=6";
            MySqlParameter[] values = new MySqlParameter[2];
            values[0] = new MySqlParameter("user_id", uid);
            values[1] = new MySqlParameter("merchant_id", merchantid);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            int count = 0;
            if (rd.Read())
            {
                if (!string.IsNullOrEmpty(rd["money"].ToString()))
                    count = Convert.ToInt32(rd["money"]);
            }
            rd.Close();
            return count;
        }
        /// <summary>
        /// 订单改为已接
        /// </summary>
        /// <param name="order_sn"></param>
        /// <returns></returns>
        public static int Updatereder(string order_sn)
        {
            string sql = "update ms_order set onreder=1 where order_sn=@order_sn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("order_sn", order_sn);
            return DBHelper.ExcutUpdate(sql, values);
        }
    }
}
